const fs = require("fs");
const path = require("path");

let filePath = path.join(__dirname , "test.txt");

let filePathWrite = path.join(__dirname , "to.txt");
//创建一个可读流
let readStream = fs.createReadStream(filePath);

//创建一个可写流
let writeStream = fs.createWriteStream(filePathWrite);
//这个readStream就是一个stream对象
// console.log(readStream);
//通过data事件进行读取
//将数据写入可写流中的方法
    /*
        1. 获取到其他文件的数据 ， 然后通过write方法将其写入
        2. 或者是获取一个可读流 ，然后通过pipe方法通过管道传输来传输数据    
    */
// readStream.on("data" , (chunk) => {
//     console.log(chunk.toString());
//     writeStream.write(chunk);
// })
readStream.on("readable" , () => {
    let content = readStream.read();
    console.dir(content);
    // console.log(readStream.read());
});